package utils

import (
	"strings"
)

func ArgMinFloat64(data []float64) int {
	if len(data) == 0 {
		return 0
	}
	minValue := data[0]
	minIndex := 0
	for i := 1; i < len(data); i++ {
		if data[i] < minValue {
			minIndex = i
			minValue = data[i]
		}
	}
	return minIndex
}

func ArgMaxFloat64(data []float64) int {
	if len(data) == 0 {
		return 0
	}
	maxValue := data[0]
	maxIndex := 0
	for i := 1; i < len(data); i++ {
		if data[i] > maxValue {
			maxIndex = i
			maxValue = data[i]
		}
	}
	return maxIndex
}

func ReverseString(data []string) []string {
	result := make([]string, len(data))
	copy(result, data)
	for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
		result[i], result[j] = result[j], result[i]
	}
	return result
}

func FilterString(data []string, filter func(ele string) bool) []string {
	filtedData := make([]string, 0)
	for _, v := range data {
		if filter(v) {
			filtedData = append(filtedData, v)
		}
	}
	return filtedData
}

func EqualString(data []string, data2 []string) bool {
	if strings.Join(data, "") == strings.Join(data2, "") {
		return true
	} else {
		return false
	}
}

func EqualInt(data, data2 []int) bool {
	if len(data) != len(data2) {
		return false
	}
	for i := 0; i < len(data); i++ {
		if data[i] != data2[i] {
			return false
		}
	}
	return true
}

func ReduceIntInt(data []int, reduce func(cur, nxt int) int, init int) int {
	for _, v := range data {
		init = reduce(init, v)
	}
	return init
}

func MapIntString(data []int, mapper func(e int) string) []string {
	result := make([]string, 0, len(data))
	for _, v := range data {
		result = append(result, mapper(v))
	}
	return result
}

func MapIntInt(data []int, mapper func(e int) int) []int {
	result := make([]int, 0, len(data))
	for _, v := range data {
		result = append(result, mapper(v))
	}
	return result
}

func MapAnyInt(data []interface{}, mapper func(e interface{}) int) []int {
	result := make([]int, 0, len(data))
	for _, v := range data {
		result = append(result, mapper(v))
	}
	return result
}
